package com.heartunderblade.rpc;

import com.heartunderblade.rpc.Registry.LocalRegistry;
import com.heartunderblade.rpc.Registry.Registry;
import com.heartunderblade.rpc.RpcPojo.ServiceMetaInfo;
import com.heartunderblade.rpc.factory.RegistryFactory;
import com.heartunderblade.rpc.server.NettyHttpServer;
import com.heartunderblade.rpc.service.HttpServer;
import com.heartunderblade.rpc.service.UserService;
import com.heartunderblade.rpc.service.impl.UserServiceImpl;

public class CoreProvider {
    public static void main(String[] args) throws Exception {

        // 框架初始化
        RpcApplication.init();

        System.out.println("Hello world!");// 提供服务
//        LocalRegistry.register(UserService.class.getName(), UserServiceImpl.class);
        //etcd
        //从工厂获取
        Registry instance = RegistryFactory.getInstance(RpcApplication.getRpcConfig().getRegistryConfig().getRegistry());
        ServiceMetaInfo serviceMetaInfo = new ServiceMetaInfo();
        serviceMetaInfo.setServiceName(UserServiceImpl.class.getName());
        serviceMetaInfo.setServiceVersion("1.0");
        serviceMetaInfo.setServiceHost("127.0.0.1");
        serviceMetaInfo.setServicePort(9000);
        instance.register(serviceMetaInfo);


        // 启动web服务
        HttpServer httpServer = new NettyHttpServer();
        // 启动web服务（从RPC框架中的全局配置中获取端口）
        httpServer.doStart(RpcApplication.getRpcConfig().getServerPort());

    }
}
